//
//  QSWorkStationProgressCell.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/5/18.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSWorkStationProgressCell.h"

@implementation QSWorkStationProgressCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self configSubView];
}

- (void)layoutSubviews{
    
    
    
}
- (void)configSubView{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.layer.cornerRadius = 8;
    self.contentView.layer.masksToBounds = YES;
    self.contentView.backgroundColor = [UIColor QSColorWhiteFFFFFF];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.mas_leading).offset(kRealValue(10));
        make.trailing.equalTo(self.mas_trailing).offset(kRealValue(-10));
        make.top.equalTo(self.mas_top).offset(kRealValue(0));
        make.bottom.equalTo(self.mas_bottom).offset(- kRealValue(10));
    }];
    self.progressView.layer.cornerRadius = 2;
    self.sliderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, kRealValue(4.f))];
    self.sliderView.backgroundColor = [UIColor colorWithHexString:@"#128BEC"];
    self.sliderView.layer.cornerRadius = 2;
    NSLog(@"1111 = %.3f", self.progressView.width);
    [self.progressView addSubview:self.sliderView];
}
- (void)setWorkModel:(QSWorkStationAllListModel *)workModel{
    _workModel = workModel;
    self.titleLabel.text = workModel.ewTitle;
    self.sendPeopleLabel.text = [NSString stringWithFormat:@"发起人：%@", workModel.ewCreateUserName];
    NSInteger lenth = workModel.ewFinishPerson.length;
    self.stateLabel.text = [NSString stringWithFormat:@"已完成：%@/%@", workModel.ewFinishPerson, workModel.ewSumPerson];
    [self.stateLabel setAttributedText:[UILabel setLabelTextColorWithString:self.stateLabel.text Range:NSMakeRange(4, lenth) andColor:[UIColor colorWithHexString:@"#128BEC"]]];
    __block CGFloat percent;
    NSLog(@"iiiiiii %.2f iiiiiii %.2f", workModel.ewFinishPerson.floatValue, workModel.ewSumPerson.floatValue);
    if (workModel.ewFinishPerson && workModel.ewSumPerson.intValue != 0) {
        percent = workModel.ewFinishPerson.floatValue / workModel.ewSumPerson.floatValue;
        if (percent > 1.0) {
            percent = 1;
        }
        if (percent <= 0) {
            percent = 0;
        }
        //    self.sliderView.width = percent * self.progressView.width;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSLog(@"1111 = %.5f, %.3f", percent, self.progressView.width);
//            [UIView animateWithDuration:1 animations:^{
                self.sliderView.width = percent * self.progressView.width;
//            }];
        });
    }else{
        self.sliderView.width = 0;
    }

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
